package com.telecom.at.front;



import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.telecom.at.db.dac.Dac;
import com.telecom.at.db.dac.Paging;
import com.telecom.at.db.model.AvgFlow;
import com.telecom.at.db.model.Flow;
import com.telecom.at.db.model.NumOfAccount;
import com.telecom.at.db.model.AvgFlowWrapper;
import com.telecom.at.db.model.BWList;
import com.telecom.at.db.model.User;

@WebServlet("/front/ListUser")
public class ListUser extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String account = request.getParameter("account");
		if (account == null)
			account = "";

		String pageNoStr = request.getParameter("pageNo");
		if (pageNoStr == null)
			pageNoStr = "0";
		int pageNo = Integer.parseInt(pageNoStr);

		String pageSizeStr = request.getParameter("pageSize");
		if (pageSizeStr == null)
			pageSizeStr = "20";
		int pageSize = Integer.parseInt(pageSizeStr);

		if (request.getParameter("lastPage") != null)
			pageNo = Integer.MAX_VALUE;
		if (request.getParameter("firstPage") != null)
			pageNo = 0;
		if (request.getParameter("previousPage") != null)
			pageNo--;
		if (request.getParameter("nextPage") != null)
			pageNo++;
		List<User> userList=null;
		User curUser = (User) request.getSession().getAttribute("curUser");
		if (curUser.getId() == 0) {
		 userList = Dac.getInstance().findUserByAccount(account);}
		else {
			userList = Dac.getInstance().findUserByAccount(curUser.getAccount());
		}
		//System.out.println(userList);
		//System.out.println(account);
		Paging<User> paging = new Paging<User>(pageSize, pageNo, userList);
		request.setAttribute("paging", paging);
		request.setAttribute("account", account);
		request.setAttribute("curUser", curUser);
		request.getRequestDispatcher("/WEB-INF/jsp/front/ListUser.jsp").forward(request, response);
		

	}
}



